// 创建空链表
List MakeEmpty() {
    List L = (List)malloc(sizeof(struct LNode)); 
    L->Next = NULL;

    return L;
}

Position Find(List L, ElementType X) {
   List cur = L;
    while(cur != NULL && cur->Data != X)
    {
        cur = cur->Next;
    }

    return (cur == NULL)? ERROR : cur;  
}

// 在位置P前插入元素X，如果P为NULL，则插入到末尾
bool Insert(List L, ElementType X, Position P) {
    List newnode = (List)malloc(sizeof(struct LNode));
    newnode->Data = X;
    newnode->Next = NULL;
    
    if(P == NULL)
    {
        List cur = L;
        while(cur->Next != NULL)
        {
            cur = cur->Next;
        }
        cur->Next = newnode;
        return true;
    }

    List cur = L;
    while(cur != NULL && cur->Next != P)
    {
        cur = cur->Next;
    }

    if(cur == NULL)
    {
        free(newnode);
        printf("Wrong Position for Insertion\n");
        return false;
    }

    newnode->Next = P;
    cur->Next = newnode;

    return true;
}

bool Delete(List L, Position P) {
    List cur = L;
    while(cur != NULL && cur->Next != P)
    {
        cur = cur->Next;
    }

    if(cur == NULL)
    {
        printf("Wrong Position for Deletion\n");
        return false;
    }

    cur->Next = P->Next;
    free(P);
    P = NULL;

    return true;
}